﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using DAL;
using NUnit.Framework;
using System.Linq.Dynamic;
using System.Linq;
using SimpComm;

namespace Bll
{
    [TestFixture]
    class 批量操作
    {

        [Test]
        public void 直接_动态排序1()
        {
            using (PizzaDataDataContext db = new PizzaDataDataContext())
            {
                DynamicOrderby dynamicOrderby = new DynamicOrderby();
                dynamicOrderby.Add("ID", "desc");
                var data = db.AdmCol.Where(p => p.ClassLevel == 2).OrderBy(dynamicOrderby.ToString()).FirstOrDefault();
            }
        }


        [Test]
        public void 直接_动态排序2()
        {
            using (PizzaDataDataContext db = new PizzaDataDataContext())
            {
                DynamicOrderby dynamicOrderby = new DynamicOrderby();
                dynamicOrderby.Add("key", "desc");
                var data = db.AdmCol.Where(p => p.AdmColID == 24).OrderBy(dynamicOrderby.ToString()).ToList();
            }
        }



        [Test]
        public void 直接_修改()
        {
            using (PizzaDataDataContext db = new PizzaDataDataContext())
            {
                db.AdmCol.UpdateBatch(p => p.AdmColID == 24, p => new AdmCol()
                                                                       {
                                                                           IsOpenWin = true,
                                                                       });
            }
        }

        [Test]
        public void 测试批量update()
        {
            using (PizzaDataDataContext db = new PizzaDataDataContext())
            {
                var entsnLs = new List<int>() { 29, 30, 31, 33 };
                var rows = db.AdmCol.UpdateBatch(p => entsnLs.Contains(p.ID), p => new AdmCol() { Url = "@100" });
            }
        }

        [Test]
        public void 批量修改()
        {
            using (PizzaDataDataContext db = new PizzaDataDataContext())
            {
                var rows = db.AdmCol.UpdateBatch(p => p.ID < 30, p => new AdmCol() { Descript = "yep1", AdmColID = 9 });
                Assert.IsTrue(rows > 0);
            }
        }
    }
}
